import axios from "axios";

//eslint-disable-next-line
export default {
    login: ({ adminName, adminPassword }) =>
        axios.get('/api/admins/login', {
            params: { adminName, adminPassword }
        })
            .then(({ data }) => data),
    reg: ({ adminName, adminPassword, phone }) =>
        axios.post('/api/admins/reg', {
            adminName, adminPassword, phone
        })
            .then(({ data }) => data),
    // 获取每页数据
    get: ({ curPage, eachPage }) =>
        axios.get('/api/adminsData', {
            params: {
                curPage,
                eachPage
            }
        }).then(({ data }) => data),

    // 删除
    delete: ({ _id }) =>
        axios.delete(`/api/adminsData`, {
            data: {
                _id
            }
        }).then(({ data }) => data),
    // 修改
    change: ({
        _id,
        adminName,
        adminPassword,
        phone }) =>
        axios.patch(`/api/adminsData/change`, {

            _id,
            adminName,
            adminPassword,
            phone
        }
        ).then(({ data }) => data),



    getOne: ({ _id }) => axios.get(`/api/adminsData/getone`, {
        params: { _id }
    }).then(({ data }) => data),


    // 保存令牌
    setToken: token => (localStorage["_t"] = token),
    // 获取令牌
    getToken: () => localStorage["_t"]
}